
function throttle(fn, delay) {
  let t = null,
      begin = Date.now();

  return function () {
    let _self = this,
        _args = arguments,
        cur = Date.now();

    clearTimeout(t);
    
    if (cur - begin >= delay) {
      fn.apply(_self, _args);
      begin = cur;
    } else {
      t = setTimeout(() => {
        fn.apply(_self, _args);
      }, delay)
    }
  }
}

